﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>bindDataSubscribe</title>
    <script src="scripts/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="scripts/bingo.js" type="text/javascript"></script>
    <script type="text/javascript">
        //定义action1
        var action1 = bingo.action(function ($view, $subs, $timeout) {
            
            //初始user数据
            $view.user = {
                name: '张三',
                age:20
            };

            //订阅$subscribe, 这里订阅$view.user.name
            $subs(function () { return $view.user.name; }, function (value) {
                //如果$view.user.name不是'张三', 将$view.user.age设为23
                if (value != '张三')
                    $view.user.age = 23;
            });

            setTimeout(function () {

                //设置$view.user.name为'李四'
                $view.user.name = '李四';

                //向订阅发布信息（同步数据）
                $view.$update();//等效于$view.$publish()

            }, 1000);

        });
    </script>
</head>
<body>
    <!--与action1连接, 形成一个新view-->
    <div bg-action="action1">
        姓名:{{user.name}}, 年龄:{{user.age}}
    </div>
</body>
</html>
